var strategy_view = {
	init:function()
	{
		var $add_account_btn = $('#add-account-btn');
		if($add_account_btn.length > 0){
			$add_account_btn.bind('click',function(){
				strategy_view.showAddAccount($(this));
			});
		}
		
		var $goback = $('#goback-btn');
		var $p=$('#goback-btn').data('p');
		if($goback.length > 0){
			$goback.bind('click',function(){
				document.location.href = "http://system.gzcanr.com/admins/strategy_manage-p-"+$p+".html";
				//history.go(-1);
				//history.back(-1);
			});
		}

	},
	showAddAccount:function($self){
		//弹窗
		var htmlContent = '';
		
		htmlContent += '<form class="login-form">';
		
		htmlContent+= '<div class="login-group">';
		htmlContent+= '<label  class="login-title">账号:</label>';
		htmlContent+= '<div class="login-input">';
		htmlContent+= '<input class="input-text" id="username-inp" placeholder="用户名" type="text"defaultshow="2-20个字母或数字组成"  checkItem="isBlank:'+"'"+'T|请填写用户名'+"'"+',checkEnWord:'+"'"+'F|只能由英文、数字、下划线的组合'+"'"+',computeChar:'+"'"+'>2<20|字数必须在2-20之内'+"'"+'" >';
		htmlContent+= '</div>';
		htmlContent+= '</div>';
		
		htmlContent+= '<div class="login-group">';
		htmlContent+= ' <label  class="login-title">密码:</label>';
		htmlContent+= '<div class="login-input">';
		htmlContent+= '<input class="input-text" id="pass-inp" placeholder="密码" type="password" defaultshow="6-30位字符,不支持空格和中文"  checkItem="isBlank:'+"'"+'T|请填写密码'+"'"+',checkPwd:'+"'"+'T|不能含有空白字符'+"'"+',checkWord:'+"'"+'T|不能包括中文'+"'"+',computeChar:'+"'"+'>6<30|字数必须在6-30之内'+"'"+'">';
		
		htmlContent+= '</div>';
		htmlContent+= '</div>';
	
		htmlContent+= ' </form>';
		
	
		layer.open({
		  type: 1,
		  title: '账号管理',
		  closeBtn: 1,
		  btnAlign: 'c', //按钮居中
		  btn: ['确定', '取消'],
		  area: ['550px', '300px'],
		  shadeClose: true,
		  content: htmlContent,
		  yes: function(){
             strategy_view.adddo($self);
          },
		  success: function(layero, index){
			  $.getScript("/js/common/validate.js");
		  }
		});
	},
	adddo:function($self){
		var $username = $('#username-inp');
		var $password = $('#pass-inp');
		var nameVal = passVal = '';
		nameVal = $.trim($username.val());
		passVal = $.trim($password.val());
		var cid = uid = 0;
 
      if(!validate()){
         return false;
	   }
	   
		if($self.data('cid')){
		   cid = $self.data('cid');
		}
		
		if($self.data('uid')){
		   uid = $self.data('uid');
		}
		
		if(nameVal==''){
			alert('请输入用户名!');
			$username.focus();
			return false;
		}
		if(passVal==''){
			alert('请输入密码!');
			$password.focus();
			return false;
		}
		
		var url = 'http://system.gzcanr.com/admins/strategy_manage.html';
		//添加处理
		$.post(url,{'uname':nameVal,'upass':passVal,'cmd':'accountdo','cid':cid,'uid':uid},function(data) {
			
			   if(data=='ok'){
			       alert('操作成功');
				   document.location.reload();	  
			   }else if(data=='error'){
				   alert('操作失败');
				   return false;
			   }
			   else if(data=='error_user'){
				   alert('该用户已经存在,请重新输入！');
				   $username.focus();
				   return false;
			   }
		});
		
		
		
	}
}


$(function(){
    strategy_view.init();
});